package cn.com.huzo.webapp.controller.oa;

import cn.com.huzo.service.oa.ToDoManager;
import huzofw.common.web.controller.BaseFormController;
import java.util.Map;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.collections4.MapUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

/**
 * 待办事项
 *
 * @author 吴旭
 */
@Controller
@RequestMapping(value = "/oa/todo")
public class ToDoController extends BaseFormController {

    // <editor-fold defaultstate="collapsed" desc="属性">
    @Resource(name = "ToDoManager")
    private ToDoManager _manager_todo;
    // </editor-fold>

    // <editor-fold defaultstate="collapsed" desc="画面处理部分">
    /**
     * 跳转到待办事项一览画面
     * <p>
     * @param request
     * @return
     * @throws java.lang.Exception
     */
    @RequestMapping("/list.html")
    public ModelAndView redirectListWnd(HttpServletRequest request) throws Exception {
        ModelAndView view = new ModelAndView();
        view.setViewName("oa.todo.list.def");
        return view;
    }

    /**
     * 跳转到待办事项编辑画面
     *
     * @return
     */
    @RequestMapping("/todo/edit.html")
    public ModelAndView redirectEditPopupWnd() {
        ModelAndView view = new ModelAndView();
        view.setViewName("oa.todo.edit.def");
        return view;
    }
    // </editor-fold>

    // <editor-fold defaultstate="collapsed" desc="数据处理部分">
    /**
     * 根据条件取得待办事项信息分页数据。
     * <p>
     * @param criterion 检索条件
     * @return 分页数据
     * @throws Exception
     */
    @RequestMapping(value = "/fetchTaskForPage.html",
            method = RequestMethod.POST)
    public @ResponseBody
    Map<String, Object> fetchTaskForPage(@RequestBody Map<String, Object> criterion) throws Exception {
        return _manager_todo.fetchTaskForPage(criterion);
    }

    /**
     * 签收。
     * <p>
     * @param criterion 审批人、任务ID
     * @return 成功标记
     * @throws Exception
     */
    @RequestMapping(value = "/assigneeTask.html",
            method = RequestMethod.POST)
    public @ResponseBody
    Map<String, Object> assigneeTask(@RequestBody Map<String, Object> criterion) throws Exception {
        return _manager_todo.assigneeTask(MapUtils.getLong(criterion, "UserId"),
                MapUtils.getString(criterion, "TaskId"));
    }
    // </editor-fold>
}
